import _ from "lodash";

interface Names {
  [key: string]: string;
}
const names: Names = {
  modelValue: "默认值",
  placeholder: "提示",
  label: "标签",
  value: "值",
  model: "数据",
  draggable: "拖动",
  "value-on-clear": "清空值",
  "append-to-body": "注入页面",
  prefix: "前缀",
  split: "分隔",
  position: "位置",
  inactive: "未激活",
  tag: "标签",
  width: "宽度",
  "native-type": "事件",
  "tab-position": "位置",
  height: "高度",
  top: "顶",
  icon: "图标",
  length: "长度",
  formatter: "格式",
  name: "名称",
  suffix: "后缀",
  class: "样式",
  text: "文字",
  bg: "背景",
  link: "链接",
  round: "圆角",
  circle: "圆形",
  loading: "加载中",
  disabled: "禁用",
  autofocus: "聚焦",
  clearable: "清空",
  show: "显示",
  password: "密码",
  autosize: "自适应大小",
  autocomplete: "自动完成",
  dark: "暗黑",
  "step-strictly": "校验",
  readonly: "只读",
  controls: "控制",
  border: "边框",
  "allow":"允许",
  "allow-half": "半选",
  multiple: "多选",
  "collapse-tags": "折叠标签",
  filterable: "支持搜索",
  "auto-insert-space": "空格",
  inline: "行内",
  "message": "消息",
  "status": "状态",
  "validate-on-rule-change": "立即验证",
  "scroll-to-error": "滚动错误",
  "collapse-tags-tooltip": "折叠提示",
  "show-word-limit": "字数限制",
  plain: "平板",
  stripe: "斑马纹",
  header: "头",
  closable: "关闭",
  addable: "添加",
  editable: "编辑",
  stretch: "拉伸",
  empty: "空",
  min: "最小",
  max: "最大",
  step: "步长",
  precisievents: "精度",
  limit: "限制",
  span: "跨度",
  layoutNum: "列排数量",
  precision: "精度",
  rows: "行数",
  format: "格式",
  start: "开始",
  end: "结束",
  type: "类型",
  size: "尺寸",
  color: "颜色",
  theme: "主题",
  innerText: "文本",
  footer: "底部",
  "cancel": "取消",
  "submit": "提交",
  "close-on-click-modal": "点击遮罩关闭",
  title: "标题",
  "copyright": "版权",
  "desc": "描述",
  "image": "图",
  "images": "图片",
  userName: "用户名",
  "register": "注册",
  "login": "登录",
  "btn": "按钮",
  "background": "背景",
  "carousel": "轮播",
  "trace": "跟踪",
  "logo": "徽章",
  "page": "页面",
  "setting": "设置",
  "banner": "横幅",
  "content": "内容",
  "menu": "菜单",
  "user": "用户",
  "active": "激活",
  "system": "系统",
  "font": "字体",
  "weight": "粗细",
  "tabs": "标签页",
  "cmpnt": "组件",
  "search": "搜索",
  "arrow": "箭头",
  "ctl": "控件",
  "one": "一",
  "level": "级",
  "bar": "栏",
  "maxlength": "最大长度",
  "query": "查询",
  "group": "分组",
  "use": "使用",
  "info": "信息",
  "table": "表",
  "line":"线",
  "highlight": "高亮",
  "current": "当前",
  "row": "行",
  "fields": "字段",
  "data":"数据",
  "no": "无",
  "options": "选项",
  "dict": "字典",
  "field": "字段",
  "id": "标识",
  "all": "全部",
  "sum": "合计",
  "summary": "汇总",
  "default": "默认",
  "expand": "展开",
  "detail": "详情",
  "list": "列表",
  "operation": "操作",
  "edit": "编辑",
  "delete": "删除",
  "add": "添加",
  "update": "更新",
  "confirm": "确认",
  "close": "关闭",
  "save": "保存",
  "reset": "重置",
  "filter": "过滤",
  "b":"-",
  "style":"样式",
  "view": "查看",
  "pagination": "分页",
  "fullscreen": "全屏",
  "dialog": "弹窗",
  "sub": "子",
  "children": "子组件",
  "cmpnts": "组件",
  "tool": "工具",
  "muiti": "多",
  "selection": "选",
};
// 尝试将输入的 label 转换为多种格式，并在 names 对象中查找
function findName(label: string): string | undefined {
  const formats = [label, _.kebabCase(label), _.camelCase(label), _.snakeCase(label)];
  for (const format of formats) {
    if (names.hasOwnProperty(format)) {
      return names[format];
    }
  }
  return undefined;
}
function findNameBySplitting(label: string) {
  // 将驼峰命名转换为下划线命名
  const snakeCaseName = _.snakeCase(label);

  // 使用下划线拆分字符串
  let names = _.split(snakeCaseName, '_');
  let rnames: string[] = []
  names.forEach((element) => {
    rnames.push(findName(element) || element)
  });
  return rnames.join('')
}

export function getName(label: string): string {
  // 尝试将输入的 label 转换为多种格式，并在 names 对象中查找
  let name = findName(label);
  if (name) return name;

  // 尝试将输入的 label 转为多个部分，并在 names 对象中查找
  name = findNameBySplitting(label);
  if (name) return name;
  return label || "";
}